]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
popupMenu: Avoid intermediate focus changes on menu switch
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 9 Feb 2022 14:32:56 +0000 (15:32 +0100)
committerMarge Bot <marge-bot@gnome.org>
Wed, 9 Feb 2022 16:44:08 +0000 (16:44 +0000)
Currently when switching from a popup menu to another in the same
manager, we first show the new menu, then hide the old menu and
remove its grab, then create a new grab for the just shown menu.

This briefly ungrabbed moment will still trigger keyboard focus
changes, that might have other visible effects. In order to fix
this, change the grabbing order so first the new grab is created
then the old one is dismissed. This ensures focus moves from the
old menu to the new menu without gaps in between.

Since a grab is tied to an active menu, but close/grab are now
slightly decoupled, also ensure closing a menu only tears down its
own grab. This is necessary for correct accounting while doing the
grab shuffling.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5039
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2166>

js/ui/popupMenu.js

index b464673626d2d3d1a22d7d4f57f5c8cf7a9b1bbc..f3e014667e302fc343e24df503ae57ef6e1e4511 100644 (file)
@@ -1356,13 +1356,15 @@ var PopupMenuManager = class {
             return;
 
         if (open) {
-            if (this.activeMenu)
-                this.activeMenu.close(BoxPointer.PopupAnimation.FADE);
+            const oldMenu = this.activeMenu;
+            const oldGrab = this._grab;
             this._grab = Main.pushModal(menu.actor, this._grabParams);
             this.activeMenu = menu;
-        } else {
-            if (this.activeMenu === menu)
-                this.activeMenu = null;
+            oldMenu?.close(BoxPointer.PopupAnimation.FADE);
+            if (oldGrab)
+                Main.popModal(oldGrab);
+        } else if (this.activeMenu === menu) {
+            this.activeMenu = null;
             Main.popModal(this._grab);
             this._grab = null;
         }